<template>
	<view>
	<cu-custom bgColor="bg-gradual-blue" :isBack="true"><block slot="backText">返回</block><block slot="content">新增周期</block></cu-custom>
		<view class="cu-form-group margin-top" >
			<view class="title">周期名称</view>
			<input placeholder="请输入周期名称" name="name" v-model="cycle.name"></input>
		</view>
		<view class="cu-form-group" >
			<view class="title">{{index==0?'选择任务日期':'开始时间'}}</view>
			<picker mode="date" :value="cycle.startTime" start="2015-09-01" end="2050-09-01" @change="StartDate">
				<view class="picker">
					{{cycle.startTime}}
				</view>
			</picker>
			
		</view>
		<view class="cu-form-group" v-if="index != 0">
			<view class="title">结束时间</view>
			<picker mode="date" :value="cycle.endTime" :start="cycle.startTime" end="2050-09-01" @change="EndDate">
				<view class="picker">
					{{cycle.endTime}}
				</view>
			</picker>
		</view>
		<button @click="submit" type="primary" form-type="submit" style="width: 90%;top: 180px;justify-content: center;">
			确认提交
		</button>
	</view>
</template>

<script>
	import request from '../../common/request';
	import common from 'common/common.js';
	export default {
		data() {
			return {
				index: -1,
				cycle:{
					startTime: '2023-9-1',
					endTime: '2023-9-9',
				},
			}
		},
		methods: {
			// 开始时间
			StartDate(e) {
				this.cycle.startTime = e.detail.value
			},
			// 结束时间
			EndDate(e) {
				this.cycle.endTime = e.detail.value
			},
			submit(){
				if(!this.cycle.name){
					uni.showToast({
						title:"名称不能为空",
						duration: 2000,
						icon:"error"
					})
					return;
				}
				var _this = this;
				request({
					url: common.api_base_url+'/cycle',
					data:{
						"cycle": _this.cycle
					},
					header:{
					},
					method: 'PUT',
					success: res => {
						uni.navigateBack({
						    delta: 1,
						});
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
			},
		}
	}
</script>

<style>

</style>
